package com.mxx.qh.activity;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.mxx.qh.IExceptionHandler;
import com.mxx.qh.interfaces.IGlobalException;

/**
 * @ClassName: BaseActivity
 * @Description: java类作用描述
 * @Author: ljf89 (刘江飞)
 * @Date: 2021/1/12-- 11:51
 * @Email: 642371742@qq.com
 */
public abstract class BaseActivity extends AppCompatActivity {
    private IGlobalException iException;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        setStatusBar();
        initView();
        initData();
        initListener();
        IExceptionHandler handler = new IExceptionHandler(iException);
        Thread.setDefaultUncaughtExceptionHandler(handler);
    }


    protected abstract int getLayoutResId();

    protected abstract void setStatusBar();

    protected abstract void initView();

    protected abstract void initData();

    protected void initListener() {
        iException = err -> {
            Toast.makeText(this, "系统错误", Toast.LENGTH_SHORT).show();
            finish();
        };
    }
}
